package com.sangmo.fts.process.factoring.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "ff_factoring_contract")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class FfFactoringContract extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50, index = true, unique = true)
    private String code;

    @One(value = "contract", target = FfContract.class, fieldset = {"id","code"}, groups = {"FfFactoringContract.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long contractId;

    @One(value = "loan", target = FfLoan.class, fieldset = {"id","acceptCode","receivableAmount","approvedAmount","rate","contractAmount","subDebtor"}, groups = {"FfFactoringContract.search","FfFactoringContract.detail" })
    @One(value = "loan", target = FfLoan.class, groups = {"FfFactoringContract.selection"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long loanId;

    @One(value = "financingCompany", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long financingId;

    @One(value = "bank", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long bankId;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal feeRate;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date dueDate;

    @One(value = "bankConfirmDocument", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"FfFactoringContract.search","FfFactoringContract.detail"})
    private Long bankConfirmDoc;

    @One(value = "sellerConfirmDocument", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"FfFactoringContract.search","FfFactoringContract.detail"})
    private Long sellerConfirmDoc;

    @DataField(index = true)
    private boolean bankConfirm;

    @DataField(index = true)
    private boolean sellerConfirm;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public Long getBankConfirmDoc() {
        return bankConfirmDoc;
    }

    public void setBankConfirmDoc(Long bankConfirmDoc) {
        this.bankConfirmDoc = bankConfirmDoc;
    }

    public Long getSellerConfirmDoc() {
        return sellerConfirmDoc;
    }

    public void setSellerConfirmDoc(Long sellerConfirmDoc) {
        this.sellerConfirmDoc = sellerConfirmDoc;
    }

    public boolean isBankConfirm() {
        return bankConfirm;
    }

    public void setBankConfirm(boolean bankConfirm) {
        this.bankConfirm = bankConfirm;
    }

    public boolean isSellerConfirm() {
        return sellerConfirm;
    }

    public void setSellerConfirm(boolean sellerConfirm) {
        this.sellerConfirm = sellerConfirm;
    }

    public Long getFinancingId() {
        return financingId;
    }

    public void setFinancingId(Long financingId) {
        this.financingId = financingId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public BigDecimal getFeeRate() {
        return feeRate;
    }

    public void setFeeRate(BigDecimal feeRate) {
        this.feeRate = feeRate;
    }
}
